﻿#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/asio.hpp>
#include "logs.h"
#include "MakePacket.h"

#include <boost/program_options.hpp>
#include <boost/exception/diagnostic_information.hpp>

#define APPNAME "AutoUpdate"


int main(int argc, char *argv[])
{
    std::string sourcePath;
    std::string appName;
    boost::program_options::options_description od("Options");
    od.add_options()
        ("help,h", "help message")
        (",s", boost::program_options::value<std::string>(&sourcePath), "app source dir")
        (",n", boost::program_options::value<std::string>(&appName), "app name");

    boost::program_options::variables_map vm;
    try
    {
        boost::program_options::store(boost::program_options::parse_command_line(argc, argv, od), vm);
        boost::program_options::notify(vm);
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
        std::cout << od << std::endl;
        return -1;
    }
    if (appName.empty() || sourcePath.empty() || vm.count("help"))
    {
        std::cout << od << std::endl;
        return -1;
    }
    //boost::filesystem::path exec{ argv[0] };
    //boost::filesystem::path workDir{ exec.parent_path() };
    MakePacket make;
    if (!make.Run(sourcePath, appName))
    {
        LOG_ERROR("MAKE PACKET ERROR!");
        return -1;
    }
    LOG_INFO("make complete!");
    return 0;
}
